package com.project.finance.product.controller;

import com.project.finance.common.po.TbProductDetail;
import com.project.finance.common.resultconfig.Result;
import com.project.finance.common.resultconfig.ResultGenerator;
import com.project.finance.product.service.DetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/*
* 理财产品详情
*/
@RestController
@RequestMapping("/api")
public class DetailController {

    @Autowired
    private DetailService detailService;


    /*
    * 查询所有理财产品详情
    */
    @RequestMapping(value = "/detail",method = RequestMethod.GET)
    public Result select(){
        List<TbProductDetail> listSelect = detailService.ListSelect();
        return ResultGenerator.apiSuccess(listSelect);
    }

    /*
    * 修改理财产品
    *
    */
    @RequestMapping(value = "/detail",method = RequestMethod.PUT)
    public Result update(@RequestBody TbProductDetail tbProductDetail){
        int i = detailService.update(tbProductDetail);
        if (i>0){
            return ResultGenerator.apiSuccess("ok");
        }else {
            return ResultGenerator.apiError("error");
        }

    }

    /*
    * 删除理财产品
    *
    */
    @RequestMapping(value = "/detail",method = RequestMethod.DELETE)
    public Result delete(@RequestParam List<Integer> productDetailId){
        int i = detailService.delete(productDetailId);
        if (i>0){
            return ResultGenerator.apiSuccess("ok");
        }else {
            return ResultGenerator.apiError("error");
        }
    }


}
